/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bmf.ice;

import com.bmf.dao.HLmanager;
import com.bmf.rest.nManagerLocal;
import common.InvalidPacketParametersException;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import network.manager.nodesAndGroupsManager.TooManyGroupsCreatedException;
import org.icefaces.application.PortableRenderer;
import org.icefaces.application.PushRenderer;

/**
 *
 * @author Tony_
 */
@ManagedBean
@ViewScoped
@Stateless
public class displayController implements Observer {
    private HLmanager manager;
    private static final String PUSH_GROUP = "display";
    private PortableRenderer portableRenderer;
    private String display;
    
    @EJB
    private nManagerLocal nManagerLocal;
    //@ManagedProperty(value="#{display}")
    //private display display;
    
    public displayController(){
        PushRenderer.addCurrentView(PUSH_GROUP);
    }
    
    //SI AGGIUNGE AGLI OSSERVATORI E FA PARTIRE HLMANAGER  
    @PostConstruct
    public void startBmf() throws InvalidPacketParametersException, IOException, TooManyGroupsCreatedException {
        PushRenderer.addCurrentView(PUSH_GROUP);
        portableRenderer = PushRenderer.getPortableRenderer();
        manager=nManagerLocal.getManager();
        manager.addObserver(this);
        manager.scheduleRequest();
    }

    @Override
    public void update(Observable o, Object arg) {
        if(arg instanceof String){
            System.out.println("STRINGA RICEVUTA - INVIO IN PUSH");
            display=String.valueOf(arg);
            push(display);
        }    
    }
    public void push(String p){
        //final PortableRenderer renderer = (PortableRenderer)FacesContext.getCurrentInstance();
        //display.manageValue(p);
        portableRenderer.render(PUSH_GROUP);
        System.out.println("PUSH EFFETTUATO");
    }
    
    public String getDisplay(){
        return display;
    }
    public void setDisplay(String display){
        this.display=display;
    }
}